package com.atguigu;

class Window2 extends Thread {

    private static int ticket = 100;

    @Override
    public void run() {
        while (true) {
            synchronized(Window2.class) {
                if (ticket > 0) {
                    System.out.println(Thread.currentThread().getName() + "：买票，票号是：" + ticket);
                    ticket--;
                } else {
                    break;
                }
            }
        }
    }
}

class WindowTest2 {
    public static void main(String[] args) {
        Window2 w1 = new Window2();
        Window2 w2 = new Window2();
        Window2 w3 = new Window2();

        w1.setName("窗口1");
        w2.setName("窗口2");
        w3.setName("窗口3");

        w1.start();
        w2.start();
        w3.start();
    }

}
